from time import sleep

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

path = Service(executable_path=r'C:\Users\Laptop\Desktop\thirty_one\chromedriver.exe')
driver = webdriver.Chrome(service=path)
driver.maximize_window()
driver.implicitly_wait(10)


'''alert类型弹窗，它只要警告信息和确定按钮'''
# driver.get('https://sahitest.com/demo/alertTest.htm')
# driver.find_element(By.NAME,'b1').click()
# sleep(2)
# # driver.get_screenshot_as_file('弹窗截图.png')
# alert = driver.switch_to.alert # 切换弹窗中
# alert.accept() # 点击确定按钮
# sleep(2)
# # driver.get_screenshot_as_file('关闭弹窗截图.png')

'''confirm弹窗，有警告信息和确定取消按钮类型的弹窗'''
# driver.get('https://sahitest.com/demo/confirmTest.htm')
# driver.find_element(By.NAME,'b1').click()
# sleep(2)
# alert = driver.switch_to.alert # 切换弹窗中
# sleep(2)
# alert.dismiss() # 点击取消
# driver.get_screenshot_as_file('关闭弹窗截图.png')

'''prompt弹窗，它在confirm弹窗基础上，多了一个输入框'''
# driver.get('https://sahitest.com/demo/promptTest.htm')
# driver.find_element(By.NAME,'b1').click()
# sleep(2)
# alert = driver.switch_to.alert # 切换弹窗中
# sleep(2)
# alert.send_keys('123456') # 在弹窗的输入框中输入内容
# sleep(2)
# alert.accept()
# driver.get_screenshot_as_file('输入内容的截图.png')